2020-2021 Sunseeker Telemetry and Lighting System
timer_b_ex2_overflowISR.c
Go to the documentation of this file.
1 /* --COPYRIGHT--,BSD
2  * Copyright (c) 2017, Texas Instruments Incorporated
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *
12  * * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  *
16  * * Neither the name of Texas Instruments Incorporated nor the names of
17  * its contributors may be used to endorse or promote products derived
18  * from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  * --/COPYRIGHT--*/
32 //******************************************************************************
33 // Timer_B, Toggle P1.0, Overflow ISR, 32kHz ACLK
34 //
35 // Description: Toggle P1.0 using software and the Timer_B overflow ISR.
36 // In this example an ISR triggers when TB overflows. Inside the ISR P1.0
37 // is toggled. Toggle rate is exactly 0.25Hz = [32kHz/FFFFh]/2. Proper use of the
38 // TBIV interrupt vector generator is demonstrated.
39 // ACLK = TBCLK = 32kHz, MCLK = SMCLK = default DCO ~ 1.045MHz
40 //
41 // Tested On: MSP430FR5739
42 // ---------------
43 // /|\| |
44 // | | |
45 // --|RST |
46 // | |
47 // | P1.0|-->LED
48 //******************************************************************************
49 #include "driverlib.h"
50 
51 void main(void)
52 {
53  //Stop WDT
54  WDT_A_hold(WDT_A_BASE);
55 
56  //Set P1.0 to output direction
57  GPIO_setAsOutputPin(
58  GPIO_PORT_P1,
59  GPIO_PIN0
60  );
61  Timer_B_clearTimerInterrupt(TIMER_B0_BASE);
62 
63  Timer_B_initContinuousModeParam param = {0};
64  param.clockSource = TIMER_B_CLOCKSOURCE_ACLK;
65  param.clockSourceDivider = TIMER_B_CLOCKSOURCE_DIVIDER_1;
66  param.timerInterruptEnable_TBIE = TIMER_B_TBIE_INTERRUPT_ENABLE;
67  param.timerClear = TIMER_B_DO_CLEAR;
68  param.startTimer = false;
69  Timer_B_initContinuousMode(TIMER_B0_BASE, &param);
70 
71  Timer_B_startCounter( TIMER_B0_BASE,
72  TIMER_B_CONTINUOUS_MODE
73  );
74 
75  __bis_SR_register(LPM3_bits + GIE); // Enter LPM3, enable interrupts
76  __no_operation(); // For debugger
77 }
78 
79 // Timer_B7 Interrupt Vector (TBIV) handler
80 #if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
81 #pragma vector=TIMERB1_VECTOR
82 __interrupt
83 #elif defined(__GNUC__)
84 __attribute__((interrupt(TIMERB1_VECTOR)))
85 #endif
86 void TIMERB1_ISR(void)
87 {
88  /* Any access, read or write, of the TBIV register automatically resets the
89  highest "pending" interrupt flag. */
90  switch( __even_in_range(TBIV,14) )
91  {
92  case 0: break; // No interrupt
93  case 2: break; // CCR1 not used
94  case 4: break; // CCR2 not used
95  case 6: break; // CCR3 not used
96  case 8: break; // CCR4 not used
97  case 10: break; // CCR5 not used
98  case 12: break; // CCR6 not used
99  case 14: // overflow
100  //Toggle P1.0
101  GPIO_toggleOutputOnPin(
102  GPIO_PORT_P1,
103  GPIO_PIN0
104  );
105 
106  break;
107  default: break;
108  }
109 }
void TIMERB1_ISR(void)
void main(void)
MPU_initThreeSegmentsParam param
__no_operation()